<template>
	<view>
		<view class="box">
			<u-cell-group :border="false">
				<u-cell title="店铺头像">
					<image :src="$wanlshop.oss(info.avatar, 100, 100)" mode="aspectFill" slot="value"
						style="width: 100rpx;height: 100rpx;margin-right: 30rpx;border-radius: 50%;"></image>
				</u-cell>
				<u-cell title="店铺名称" :value="info.shopname"></u-cell>
			</u-cell-group>
		</view>
		<view class="box">
			<view class="" style="font-size: 36rpx;margin-bottom: 20rpx;">
				店铺资格证
			</view>
			<view class="">
				<u-upload :fileList="fileList" name="1" :maxCount="5" @afterRead="afterRead" @delete="deletePic"
					:multiple="true"></u-upload>
			</view>
		</view>
		<view class="btn" @click="save">
			保存
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				fileList: [],
			}
		},
		async onLoad() {
			this.getInfo()
		},
		methods: {
			async getInfo() {
				await uni.request({
					url: '/index/shopInfo',
					method: "GET",
					header: {
						isAdmin: true,
						token: uni.getStorageSync("shop_login_token")
					},
					success: res => {
						this.info = res.data.shopInfo;
						if (res.data.shopInfo.zg_images) {
							res.data.shopInfo.zg_images.split(',').forEach(item => {
								this.fileList.push({
									url: "https://fen.fuliaoxx.com/" + item
								})
							})
						}

					}
				});
			},
			deletePic(e) {
				this.fileList.splice(e.index, 1)
			},
			async save() {
				let imgs = ""
				if (this.fileList.length > 0) {
					imgs = this.fileList.map(item => item.key).join(',');
				}

				await uni.request({
					url: '/index/zg_images',
					method: "GET",
					header: {
						isAdmin: true,
						token: uni.getStorageSync("shop_login_token")
					},
					data: {
						zg_images: imgs
					},
					success: res => {
						console.log(res)
						if (res.code == 1) {
							uni.showToast({
								icon: "none",
								title: "保存成功"
							})
							this.getInfo()
						}
					}
				});
			},
			async afterRead(e) {
				console.log(e)
				let that = this;
				uni.showLoading({
					mask: true,
					title: "上传中"
				})
				e.file.forEach(it1 => {
					uni.uploadFile({
						url: 'https://fen.fuliaoxx.com/api/common/upload', // 接口url
						filePath: it1.url,
						name: 'file',

						header: {
							isAdmin: true,
							token: uni.getStorageSync("shop_login_token")
						},
						success: async (res) => {
							let json = JSON.parse(res.data)
							console.log(JSON.parse(res.data))
							// that.model.image = json.data.url;
							that.fileList = [...that.fileList, {
								url: json.data
									.fullurl,
								key: json.data
									.url
							}]
							uni.hideLoading()
						},
					})
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.btn {
		background-color: black;
		margin: 30rpx;
		margin-top: 100rpx;
		padding: 30rpx;
		text-align: center;
		border-radius: 100px;
		color: white;
		font-size: 30rpx;
	}

	.box {
		margin: 30rpx;
		padding: 30rpx;
		border-radius: 20rpx;
		background-color: white;
	}
</style>